/*
 * Copyright 2010 Kevin Bourrillion.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package kevinb9n.tobago;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;

import java.math.BigInteger;
import java.util.Random;

public class Main {
  private static final BigInteger MIN_SEED = BigInteger.valueOf(Long.MIN_VALUE);

  public static void main(String[] args) {
    System.out.println();

    long seed = (args.length == 1)
        ? new BigInteger(args[0], 36).add(MIN_SEED).longValue()
        : new Random().nextLong();

    BigInteger nonnegativeSeed = BigInteger.valueOf(seed).subtract(MIN_SEED);
    System.out.println("Setup id: " + nonnegativeSeed.toString(36)
        + " (pass this on the command line to see the same board setup)");
    Random r = new Random(seed);

    long nanos = System.nanoTime();
    Island island = Island.random(r);
    long elapsed = System.nanoTime() - nanos;
    new TextReport(island).printTo(System.out);
    System.out.println("time to compute: "
        + (MILLISECONDS.convert(elapsed, NANOSECONDS) + 1) + " ms");
  }
}
